﻿package mortal.game.view.copy.towerCopy.panel
{
    import com.mui.containers.globalVariable.*;
    import com.mui.controls.*;
    import extend.language.*;
    import fl.data.*;
    import flash.events.*;
    import flash.utils.*;
    import mortal.component.window.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.view.common.*;
    import mortal.game.view.copy.towerCopy.*;
    import mortal.game.view.copy.towerCopy.cellrender.*;
    import mortal.mvc.core.*;
    import mortal.mvc.interfaces.*;

    public class TowerSweepBagPanel extends BaseWindow
    {
        private var _curlv:GTextFiled;
        private var _award:GTileList;
        private var _getAwardBtn:GButton;
        private static var _instance:TowerSweepBagPanel;

        public function TowerSweepBagPanel(param1:ILayer = null)
        {
            super(param1);
            setSize(270, 200);
            titleHeight = 60;
            title = "" + Language.getString(71001);
            return;
        }// end function

        private function onGetAward(event:MouseEvent) : void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.TowerGetReward, TowerModule.copyCode));
            return;
        }// end function

        private function onTowerSweepPackUpdate(param1:Object = null) : void
        {
            var _loc_4:String = null;
            var _loc_5:ItemData = null;
            var _loc_2:* = Cache.instance.pack.towerScanPackCache.allNotNullItems;
            var _loc_3:* = Cache.instance.copy.tower.getTowerInfo(TowerModule.copyCode).money;
            for (_loc_4 in _loc_3)
            {
                
                _loc_5 = new ItemData(int(_loc_4));
                _loc_5.extData = int(_loc_3[_loc_4]);
                _loc_5.itemAmount = int(_loc_3[_loc_4]);
                _loc_2.push(_loc_5);
            }
            this._award.dataProvider = new DataProvider(_loc_2);
            this._award.drawNow();
            return;
        }// end function

        override public function show(param1:int = 0, param2:int = 0) : void
        {
            super.show(param1, param2);
            this.onTowerSweepPackUpdate();
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._curlv = UIFactory.gTextField("", 30, 30, 220, 20, this);
            this._award = UIFactory.tileList(50, 60, 200, 90, this);
            this._award.setStyle("cellRenderer", TowerRewardsCellRenderer);
            this._award.columnWidth = 45;
            this._award.rowHeight = 45;
            this._award.direction = GBoxDirection.HORIZONTAL;
            this._getAwardBtn = UIFactory.gButton("" + Language.getString(71002), 100, 170, 72, 28, this);
            this._getAwardBtn.configEventListener(MouseEvent.CLICK, this.onGetAward);
            NetDispatcher.addCmdListener(ServerCommand.TowerSweepPackUpdate, this.onTowerSweepPackUpdate);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            NetDispatcher.removeCmdListener(ServerCommand.TowerSweepPackUpdate, this.onTowerSweepPackUpdate);
            this._curlv.dispose(param1);
            this._curlv = null;
            this._award.dispose(param1);
            this._award = null;
            this._getAwardBtn.dispose(param1);
            this._getAwardBtn = null;
            return;
        }// end function

        public static function get instance() : TowerSweepBagPanel
        {
            if (!_instance)
            {
                _instance = new TowerSweepBagPanel;
            }
            return _instance;
        }// end function

        public static function get isViewShow() : Boolean
        {
            return _instance && !_instance.isHide;
        }// end function

    }
}
